package it.sd.pwframework.business.bean;

public class PwProperty implements Comparable<PwProperty> {

	private String name;
	
	private PwPropertyType type;
	
	private String subtype;
	
	private boolean lazy=true;
	
	private boolean nullable=true;

	private int length = 0;
	
	private int order = 999;
	private String label =null;
	private boolean searcheable = false;
	
	private String validator = null;

	public PwProperty(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isLazy() {
		return lazy;
	}

	public void setLazy(boolean lazy) {
		this.lazy = lazy;
	}

	public boolean getNullable() {
		return nullable;
	}

	public void setNullable(boolean nullable) {
		this.nullable = nullable;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (lazy ? 1231 : 1237);
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + (nullable ? 1231 : 1237);
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PwProperty other = (PwProperty) obj;
		if (lazy != other.lazy)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (nullable != other.nullable)
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "PwProperty [name=" + name + ", type=" + type + ", subtype="
				+ subtype + ", lazy=" + lazy + ", nullable=" + nullable
				+ ", length=" + length + ", order=" + order + ", label="
				+ label + ", searcheable=" + searcheable + "]";
	}

	public PwPropertyType getType() {
		return type;
	}

	public void setType(PwPropertyType type) {
		this.type = type;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public String getSubtype() {
		return subtype;
	}

	public void setSubtype(String subtype) {
		this.subtype = subtype;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public String getLabel() {
		if (label==null) {
			return name;
		} else {
			return label;
		}
	}

	public void setLabel(String label) {
		if ((label!=null) && (label.trim().length()>0)) {
			this.label = label.trim();
		}
	}

	public boolean getSearcheable() {
		return searcheable;
	}

	public void setSearcheable(boolean searcheable) {
		this.searcheable = searcheable;
	}

	@Override
	public int compareTo(PwProperty o) {

		if (getOrder() < o.getOrder()) {
			return -1;
		} else if(getOrder() > o.getOrder()) {
			return 1;
		} else {
			return getLabel().compareTo(o.getLabel());
		}
	}

	public String getValidator() {
		return validator;
	}

	public void setValidator(String validator) {
		if ( (validator!=null) && (validator.trim().length()>0)) {
			this.validator = validator;	
		} else {
			this.validator = null;
		}
		
	}

	

	
	
	
	
	
	
}
